package com.loan.monitor.admin.util;

import org.apache.commons.lang3.StringUtils;

/**
 * @author shiguang on 2022/6/22 11:36
 */
public class UrlUtils {

    public static String getIpAddress(String url) {
        if (StringUtils.isBlank(url)) {
            throw new RuntimeException("从URL中获取IP地址时，URL不能为空！！");
        }
        String[] urls = url.split(":");
        if (urls.length < 2) {
            throw new RuntimeException("从URL中获取IP地址时，URL输入不合法！！");
        }
        String ipAddress = urls[0];
        ipAddress = ipAddress.replace("//", "/");
        urls = ipAddress.split("/");
        ipAddress = urls[1];
        return ipAddress;
    }

}
